<?php
/**
 * 会员中心
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');

class member_indexControl extends MobileControl {
	private $voucherstate_arr;
	
	public function __construct(){
		parent::__construct();
		$this->isLogin();
	}
    public function goodsFavsNum($fav_type='goods'){
        $gfavs_num = 0;
        //查询会员上次登陆时间
        $sql = "select member_old_login_time from #__member where member_id ='{$_SESSION['member_id']}' ";
        $row_time = Db::queryRow($sql);
        $old_login_time = $row_time['member_old_login_time'];
        if($fav_type=='stores'){
            $sql = "select count(*) as c from #__favorites f left join #__store s on f.fav_id=s.store_id where f.fav_type='store' and f.member_id='{$_SESSION['member_id']}' and s.store_state=1 and f.fav_time>$old_login_time";
            $row_num = Db::queryRow($sql);
            $sfavs_num = $row_num['c'];
            return $sfavs_num;
        }
        if($fav_type=='brands'){
            $sql="select count(*) as c from #__brand b left join #__brand_favorites bf on b.brand_id=bf.brand_fav_id where member_id ='{$_SESSION['member_id']}' and b.brand_show=1 and bf.brand_fav_time>$old_login_time";
            $row_num = Db::queryRow($sql);
            $bfavs_num = $row_num['c'];
            return $bfavs_num;
        }
        $sql = "select count(*) as c from #__favorites f left join #__goods g on f.fav_id=g.goods_id where f.fav_type='goods' and member_id='{$_SESSION['member_id']}' and g.goods_state=0 and g.goods_show=1 and f.fav_time>$old_login_time";
        $row_num = Db::queryRow($sql);
        $gfavs_num = $row_num['c'];

        return $gfavs_num;
    }
	//会员中心首页
	public function indexOp(){
		//查询会员信息
		$this->get_member_info();
        //三个收藏数量，从上次登陆时间算起
        $gfavs = $this->goodsFavsNum('goods'); //商品
        $sfavs = $this->goodsFavsNum('stores'); //商城
        $bfavs = $this->goodsFavsNum('brands'); //品牌
        Tpl::output('gfavs',$gfavs);
        Tpl::output('sfavs',$sfavs);
        Tpl::output('bfavs',$bfavs);
        //信息输出
		$newInfoNum = $this->receivedCommonNewNum() + $this->receivedSystemNewNum() + $this->receivedPersonalNewNum();
        //
        /*首页订单显示：新模板不用了*/
      //  $this->orderlist();

		Tpl::output('newInfoNum',$newInfoNum);
		Tpl::output('nchash',substr(md5(SiteUrl.$_GET['act'].$_GET['op']),0,8));
	
		Tpl::showpage('member_index');
	}
    public function ajax_echoOp(){
        echo "ajax-echo from member_indwx";
    }
	
	//账户余额信息
	public function predepositOp(){
		//查询会员信息
		$this->get_member_info();
		//领取的代金券状态
		$this->voucherstate_arr = array('unused'=>array(1,'未使用'),'used'=>array(2,'已使用'),'expire'=>array(3,'已过期'));
		//判断系统是否开启代金券功能
		if (intval(C('voucher_allow')) !== 1){
			Tpl::output('voucher_allow',false);
		}else{
			//检查过期的代金券，状态设置为过期(vouchet_state=3)
			$this->check_voucher_expire();
			$field = "v.voucher_id,v.voucher_code,v.voucher_title,v.voucher_desc,v.voucher_start_date,v.voucher_end_date,v.voucher_price,v.voucher_limit,v.voucher_state,v.voucher_order_id,v.voucher_store_id,s.store_name,s.store_id,s.store_domain,vt.voucher_t_customimg";
			$sql = "SELECT $field FROM #__voucher AS v LEFT JOIN #__store AS s ON v.voucher_store_id = s.store_id LEFT JOIN #__voucher_template AS vt ON v.voucher_t_id = vt.voucher_t_id WHERE voucher_owner_id = '{$_SESSION['member_id']}' AND voucher_state = '1'";
			$list = Db::queryAll($sql);
			
			if(!empty($list) && is_array($list)){
				foreach ($list as $key=>$val){
					if (!$val['voucher_t_customimg'] || !is_file(BasePath.DS.ATTACH_VOUCHER.DS.$val['store_id'].DS.$val['voucher_t_customimg'])){
						$list[$key]['voucher_t_customimg'] = defaultGoodsImage('small');
					}else{
						$list[$key]['voucher_t_customimg'] = SiteUrl.DS.ATTACH_VOUCHER.DS.$val['store_id'].DS.$val['voucher_t_customimg']."_small.".get_image_type($val['voucher_t_customimg']);
					}
				}
			}
			Tpl::output('voucher_allow',true);
			Tpl::output('voucher_list', $list);//echo '<pre>';print_r($list);die;
		}
		
		Tpl::showpage('member_predeposit');		
	}

//删除代金券
		public function del_voucherOp(){
			if ($_GET['sub'] == 'ok') {
			if (is_array ( $_POST ['del_id'] ) && ! empty ( $_POST ['del_id'] )) {
				foreach ( $_POST ['del_id'] as $v ) {
					$v = intval ( $v );
					db::delete ( 'voucher', "voucher_id='{$v}'" );
				}
				showMessage ( '删除代金券成功' );
			} else {
				showMessage ( '未选择删除代金券' );
			}
		}
		}
	 //检查过期的代金券，状态设置为过期(vouchet_state=3)
    private function check_voucher_expire() {
        $model = Model();
        $model->table('voucher')->where(array('voucher_owner_id'=>$_SESSION['member_id'],'voucher_state'=>$this->voucherstate_arr['unused'][0],'voucher_end_date'=>array('lt',time())))->update(array('voucher_state'=>$this->voucherstate_arr['expire'][0]));
    }
	
	//账户中心
	public function account_indexOp(){
		Tpl::showpage('account_index');
	}
	
	//收货地址列表
	public function addressOp(){
		$address_class =new addressModel();
		
		//ajax删除收货地址
		if($_GET['t'] == 'del'){
			$id = (int)$_GET['address_id'];
			if($id > 0){
				$rs = $address_class->delAddress($id);
				if($rs){
					echo json_encode(array('state'=>true));exit;
				}else{
					echo json_encode(array('state'=>false));exit;
				}
			}else{
				echo json_encode(array('state'=>false));exit;
			}
		}
		
		$address_list = $address_class->getAddressList(array('member_id'=>$_SESSION['member_id']));
		Tpl::output('address_list',$address_list);
		Tpl::showpage('address_index');
	}
	
	//新增/修改收货地址
	public function address_modOp(){
	    
	    //记录来路
	    if($_GET['is_order']){
	        $_SESSION['add_user_address_http_referer']  = $_SERVER['HTTP_REFERER'];
	    }
	    
		$address_class =new addressModel();

		if($_GET['form_submit'] == 'ok'){
			$obj_validate = new Validate();
			$obj_validate->validateparam = array(
				array("input"=>$_GET["true_name"],"require"=>"true","message"=>'收货人不能为空'),
				array("input"=>$_GET["area_id"],"require"=>"true","validator"=>"Number","message"=>'所在地区选择不正确'),
				array("input"=>$_GET["area_info"],"require"=>"true","message"=>'所在地区信息不能为空'),
				array("input"=>$_GET["address"],"require"=>"true","message"=>'详细地址不能为空'),
				array("input"=>$_GET['mob_phone'],'require'=>'true','message'=>'手机号码不能为空'),
				/*array("input"=>$_GET['tel_phone'],'require'=>'true','message'=>'电话号码不能为空')*/
			);
			
			$error = $obj_validate->validate();
			if ($error != ''){
				mobileJump($error);
			}
			include BasePath.DS.'data/area/areaall.php';
			$area_id = (int)$_GET['area_id'];
			$_GET['city_id'] = $area_array[$area_id]['area_parent_id'];
			
			if (intval($_GET['id']) > 0){
				$rs = $address_class->updateAddress($_GET);
				if (!$rs){
					mobileJump('修改失败');
				}
			}else {
				$rs = $address_class->addAddress($_GET);
				if (!$rs){
					mobileJump('添加失败');
				}
			}
			//第一次购物跳转到收货地址添加页面，添加完毕回到订单页面
			if(isset($_SESSION['add_user_address_http_referer'])){
			    $referer = $_SESSION['add_user_address_http_referer'];
			    unset($_SESSION['add_user_address_http_referer']);
				mobileJump('操作成功', $referer);
			}else{
				mobileJump('操作成功','index.php?act=member_index&op=address');
			}
		}
		
		if((int)$_GET['address_id'] > 0){
			$sql = "SELECT * FROM #__address WHERE address_id = '{$_GET['address_id']}'";
			$address = Db::queryRow($sql);
			Tpl::output('address',$address);
            Tpl::output('addr_edit',1);
		}
		Tpl::showpage('address_add');
	}
	//修改登录密码
	public function mod_pwdOp(){
		
		 /**
         * 实例化模型
         */
        $model_member = new memberModel();
        /**
         * 修改密码
         */
        $mem = new memberModel();
        $memberInfo_all = $mem->infoMember(array('member_id' => $_SESSION['member_id']));
        if (chksubmit()) {
            /**
             * 填写密码信息验证
             */
            $obj_validate = new Validate();
            $obj_validate->validateparam = array(
                array("input" => $_POST["orig_password"], "require" => "true", "message" => '原始密码不能为空'),
                array("input" => $_POST["new_password"], "require" => "true", "message" => '新密码不能为空'),
                array("input" => $_POST["confirm_password"], "require" => "true", "validator" => "Compare", "operator" => "==", "to" => $_POST["new_password"], "message" => '新密码与确认密码不一致'),
            );
            $error = $obj_validate->validate();
            if ($error != '') {
                mobileJump($error);
            }
            if ($memberInfo_all['member_passwd'] == md5(trim($_POST['new_password']))) {
                mobileJump('新密码必须与原密码不相同');
            }
            $member_info = $model_member->where(array('member_name' => trim($_SESSION['member_name']), 'member_passwd' => md5(trim($_POST['orig_password']))))->find();
            if (empty($member_info)) {
                mobileJump('原始密码不正确');
            }
            $update = $model_member->update(array('member_passwd' => md5(trim($_POST['new_password'])), 'member_id' => $_SESSION['member_id']));
            if ($update) {
                if (C('ucenter_status')) {
                    $model_ucenter = new ucenterModel();
                    $model_ucenter->userEdit(array('login_name' => $_SESSION['member_name'], 'old_password' => trim($_POST['orig_password']), 'password' => trim($_POST['new_password'])));
                }
				@session_destroy();
				 mobileJump('修改成功,请重新登录', 'index.php?act=login');
            } else {
				 mobileJump('修改失败');
            }
        }
		
		Tpl::showpage('member_password');
	}
	
	//交易验证支付密码
	public function checkPayPwdOp() {
		$password=$_POST['password'];
		$mem=new memberModel();
		$id=$_SESSION['member_id'];
		$info=$mem->infoMember(array('member_id'=>$id),"paypassword");
		if(md5($password)==$info['paypassword']){
			exit("true");
		}else{
			exit("false"); 
		}
	}
	
	/**
	 * 找回支付密码发送短信
	 */
	public function resetPayPwdOp(){
		
		if(trim($_SESSION['member_mobile']) == ''){
			showMessage('请先绑定手机号码','','json');
		}
		$member_model	=new memberModel();
		/**
		 * 产生密码
		 */
		$new_password	= rand(100000,999999);
		if(!($member_model->updateMember(array('paypassword'=>md5($new_password)),$_SESSION['member_id']))){
			showMessage('支付密码重置失败','','json');
		}
		/**
		 * 发送短信
		 */
		if(mobileModel::send($_SESSION['member_mobile'], '您新的支付密码为：' . $new_password.'，为确保账号资金安全，请您登陆网站修改支付密码！')){
			showMessage('新的支付密码已发送到您的手机，请注意查收','','json');
		}else{
			showMessage('短信发送失败','','json');
		}
	}
	
	//修改支付密码
	public function mod_pay_pwdOp(){
		if($_SESSION['member_mobile'] == ''){
			mobileJump('请先绑定手机号码','index.php?act=member_index&op=mod_mobile');
		}
		if (chksubmit()) {
			if($_POST['step'] == 'false'){
				$obj_validate = new Validate();
				$obj_validate->validateparam = array(
					array("input" =>$_POST["code"], "require" => "true", "message" => "验证码不能为空"),
				);
				$error = $obj_validate->validate();
				if ($error != '') {
					mobileJump($error);
				}
				$send_code = md5($_POST['code']);
				//获取验证信息
				$sql = "SELECT * FROM #__member_mobile_validation WHERE member_id = '{$_SESSION['member_id']}' AND valid_type = '".MOBILE_VALID_TYPE_UPDATE_PAY_PASS."' AND valid_status = '1' AND send_code = '$send_code' ORDER BY send_time DESC";
				$info = Db::queryRow($sql);
				//核对手机号码
				if(empty($info) || !is_array($info) || $_POST['mobile'] != $info['valid_mobile']){
					mobileJump('验证信息错误');
				}
				$nowTime = time();
				//核对验证码期限
				if($nowTime > ($info['send_time']+(MOBILE_VALID_ACTIVE_TERM * 60))){
					mobileJump('该验证码已过有效期，请重新获取！');
				}
				$rs = Db::update('member_mobile_validation',array('valid_status'=>EMAIL_VALID_STATUS_CHECK,'check_time'=>$nowTime),"valid_id = '{$info['valid_id']}'");
				$c = base64_encode($send_code);
				if($rs){
					mobileJump('验证成功',"index.php?act=member_index&op=mod_pay_pwd&step=true&c=$c");
				}else{
					mobileJump('验证失败');
				}
			}else{
				$obj_validate = new Validate();
				$obj_validate->validateparam = array(
					array("input" => $_POST["new_password"], "require" => "true", "message" => '新密码不能为空'),
					array("input" => $_POST["confirm_password"], "require" => "true", "validator" => "Compare", "operator" => "==", "to" => $_POST["new_password"], "message" => '新密码与确认密码不一致'),
				);
				$error = $obj_validate->validate();
				if ($error != '') {
					mobileJump($error);
				}
				$update = Db::update('member',array('paypassword' => md5(trim($_POST['new_password']))), "member_id = '{$_SESSION['member_id']}'");
				if ($update) {
					 mobileJump('修改成功', 'index.php?act=member_index&op=account_index');
				} else {
					 mobileJump('修改失败');
				}
			}
		}else{
			if ($_GET['step'] == true) {
				//防止直接跳转第二步修改支付密码，先进行第一步验证通过方可跳转到修改支付密码页
				$c = base64_decode($_GET['c']);
				//获取验证信息
				$sql = "SELECT * FROM #__member_mobile_validation WHERE member_id = '{$_SESSION['member_id']}' AND valid_type = '".MOBILE_VALID_TYPE_UPDATE_PAY_PASS."' AND valid_status = '2' AND send_code = '$c' ORDER BY send_time DESC";
				$info = Db::queryRow($sql);
				if(empty($info ) || !is_array($info)){
					mobileJump('请先验证身份信息','index.php?act=member_index&op=mod_pay_pwd');
					exit;
				}
				Tpl::output('step',true);
			}else{
				Tpl::output('step',false);
			}
			Tpl::showpage('member_pay_password');
		}
	}
	
	/**
     *   修改支付密码发送手机短信验证码
     */
    public function ajax_get_code_payOp()
    {
		if(!preg_match('/^1[3|5|7|8]{1}\d{9}$/i',$_GET['mobile'])){
			echo json_encode(array('state'=>false));exit;
		}
		$type = MOBILE_VALID_TYPE_UPDATE_PAY_PASS;
		$send_content = '修改支付密码验证码';
        $new_code = rand(100000, 999999);
        $mobile_member = new mobileModel();
        //存入数据库
        $save_code = $mobile_member->save_code(array(
            'member_id' => $_SESSION['member_id'],
            'valid_mobile' => $_GET['mobile'],
            'valid_type' => $type,
            'send_code' => md5($new_code),
            'send_content' => $send_content,
            'valid_status' => MOBILE_VALID_STATUS_SEND,
            'send_time' => time(),
        ));
        if ($save_code > 0) {
            //发送短信
           	$send_msg = mobileModel::send($_GET['mobile'], '您当前正在进行支付密码修改操作，您的手机验证码是：' . $new_code.'，此验证码30分钟内有效，请及时完成操作！');
			$result['code'] = $new_code;
            $result['state'] = true;
            echo json_encode($result);exit;
        }else{
			echo json_encode(array('state'=>false));exit;
		}
    }
	
	 /**
     *   绑定发送手机短信验证码
     */
    public function ajax_get_code_mobileOp()
    {
		if(!preg_match('/^1[3|5|7|8]{1}\d{9}$/i',$_GET['mobile'])){
			echo json_encode(array('state'=>false,'msg'=>'手机号码不正确'));exit;
		}
		if($_GET['type'] == 'old'){
			$type = MOBILE_VALID_TYPE_OLD_MOBILE;
			$send_content = '往旧手机发送验证码';
		}else{
			//验证该手机号码是否已经绑定了其它账号
			$sql = "SELECT * FROM #__member WHERE member_mobile = '{$_GET['mobile']}'";
			$rs = Db::queryRow($sql);
			if(!empty($rs) && is_array($rs)){
				echo json_encode(array('state'=>false,'msg'=>'手机号码已存在'));exit;
			}
			$type = MOBILE_VALID_TYPE_NEW_MOBILE;
			$send_content = '往新手机发送验证码';
		}
        $new_code = rand(100000, 999999);
        $mobile_member = new mobileModel();
        //存入数据库
        $save_code = $mobile_member->save_code(array(
            'member_id' => $_SESSION['member_id'],
            'valid_mobile' => $_GET['mobile'],
            'valid_type' => $type,
            'send_code' => md5($new_code),
            'send_content' => $send_content,
            'valid_status' => MOBILE_VALID_STATUS_SEND,
            'send_time' => time(),
        ));
        if ($save_code > 0) {
            //发送短信
           	$send_msg = mobileModel::send($_GET['mobile'], '您当前正在进行手机绑定修改操作，您的手机验证码是：' . $new_code.'，此验证码30分钟内有效，请及时完成操作！');
            echo json_encode(array('state'=>true));exit;
        }else{
			echo json_encode(array('state'=>false,'msg'=>'验证码发送失败'));exit;
		}
    }
	
	//修改/绑定手机
	public function mod_mobileOp(){
		if (chksubmit()) {
			//绑定手机操作
			if (isset($_SESSION['member_mobile']) && $_SESSION['member_mobile'] == '') {
				$obj_validate = new Validate();
				$obj_validate->validateparam = array(
					array("input" =>$_POST["mobile"], "require" => "true", "message" => "手机号码不能为空"),
					array("input" =>$_POST["code"], "require" => "true", "message" => "验证码不能为空"),
				);
				$error = $obj_validate->validate();
				if ($error != '') {
					mobileJump($error);
				}
				$send_code = md5($_POST['code']);
				//获取验证信息
				$sql = "SELECT * FROM #__member_mobile_validation WHERE member_id = '{$_SESSION['member_id']}' AND valid_type = '".MOBILE_VALID_TYPE_NEW_MOBILE."' AND valid_status = '1' AND send_code = '$send_code' ORDER BY send_time DESC";
				$info = Db::queryRow($sql);
				//核对手机号码
				if(empty($info) || !is_array($info) || $_POST['mobile'] != $info['valid_mobile']){
					mobileJump('验证信息错误');
				}
				$nowTime = time();
				//核对验证码期限
				if($nowTime > ($info['send_time']+(MOBILE_VALID_ACTIVE_TERM * 60))){
					mobileJump('该验证码已过有效期，请重新获取！');
				}
				$update =Db::update('member',array('member_mobile' => trim($_POST['mobile'])), "member_id = '{$_SESSION['member_id']}'");
				if($update){
					$_SESSION['member_mobile'] = $_POST['mobile'];
					Db::update('member_mobile_validation',array('valid_status'=>EMAIL_VALID_STATUS_CHECK,'check_time'=>$nowTime),"valid_id = '{$info['valid_id']}'");
					mobileJump('验证成功','index.php?act=member_index&op=account_index');
				}else{
					mobileJump('验证失败');
				}
			}elseif (isset($_SESSION['member_mobile']) && $_SESSION['member_mobile'] != ''){
				//验证旧手机操作
				if($_POST['step'] == 'false'){
					$obj_validate = new Validate();
					$obj_validate->validateparam = array(
						array("input" =>$_POST["code"], "require" => "true", "message" => "验证码不能为空"),
					);
					$error = $obj_validate->validate();
					if ($error != '') {
						mobileJump($error);
					}
					$send_code = md5($_POST['code']);
					//获取验证信息
					$sql = "SELECT * FROM #__member_mobile_validation WHERE member_id = '{$_SESSION['member_id']}' AND valid_type = '".MOBILE_VALID_TYPE_OLD_MOBILE."' AND valid_status = '1' AND send_code = '$send_code' ORDER BY send_time DESC";
					$info = Db::queryRow($sql);
					//核对手机号码
					if(empty($info) || !is_array($info) || $_POST['old_mobile'] != $info['valid_mobile']){
						mobileJump('验证信息错误');
					}
					$nowTime = time();
					//核对验证码期限
					if($nowTime > ($info['send_time']+(MOBILE_VALID_ACTIVE_TERM * 60))){
						mobileJump('该验证码已过有效期，请重新获取！');
					}
					$rs = Db::update('member_mobile_validation',array('valid_status'=>EMAIL_VALID_STATUS_CHECK,'check_time'=>$nowTime),"valid_id = '{$info['valid_id']}'");
					$c = base64_encode($send_code);
					if($rs){
						mobileJump('验证成功',"index.php?act=member_index&op=mod_mobile&step=true&c=$c");
					}else{
						mobileJump('验证失败');
					}
				//修改新手机操作
				}elseif($_POST['step'] == 'true'){
					//echo '<pre>';print_r($_POST);die;
					$obj_validate = new Validate();
					$obj_validate->validateparam = array(
						array("input" =>$_POST["mobile"], "require" => "true", "message" => "手机号码不能为空"),
						array("input" =>$_POST["code"], "require" => "true", "message" => "验证码不能为空"),
					);
					$error = $obj_validate->validate();
					if ($error != '') {
						mobileJump($error);
					}
					if($_POST['mobile'] == $_SESSION['member_mobile']){
						mobileJump('新手机号码不能和旧手机号码一致');
					}
					$send_code = md5($_POST['code']);
					//获取验证信息
					$sql = "SELECT * FROM #__member_mobile_validation WHERE member_id = '{$_SESSION['member_id']}' AND valid_type = '".MOBILE_VALID_TYPE_NEW_MOBILE."' AND valid_status = '1' AND send_code = '$send_code' ORDER BY send_time DESC";
					$info = Db::queryRow($sql);
					//核对手机号码
					if(empty($info) || !is_array($info) || $_POST['mobile'] != $info['valid_mobile']){
						mobileJump('验证信息错误');
					}
					$nowTime = time();
					//核对验证码期限
					if($nowTime > ($info['send_time']+(MOBILE_VALID_ACTIVE_TERM * 60))){
						mobileJump('该验证码已过有效期，请重新获取！');
					}
					$update =Db::update('member',array('member_mobile' => trim($_POST['mobile'])), "member_id = '{$_SESSION['member_id']}'");
					if($update){
						$_SESSION['member_mobile'] = $_POST['mobile'];
						Db::update('member_mobile_validation',array('valid_status'=>EMAIL_VALID_STATUS_CHECK,'check_time'=>$nowTime),"valid_id = '{$info['valid_id']}'");
						mobileJump('验证成功','index.php?act=member_index&op=account_index');
					}else{
						mobileJump('验证失败');
					}
				}
			}
		}else{
			if ($_SESSION['member_mobile'] != '' && $_GET['step'] == true) {
				//防止直接跳转第二步修改手机号码，先进行第一步验证通过方可跳转到修改手机号码页
				$c = base64_decode($_GET['c']);
				//获取验证信息
				$sql = "SELECT * FROM #__member_mobile_validation WHERE member_id = '{$_SESSION['member_id']}' AND valid_type = '".MOBILE_VALID_TYPE_OLD_MOBILE."' AND valid_status = '2' AND send_code = '$c' ORDER BY send_time DESC";
				$info = Db::queryRow($sql);
				if(empty($info ) || !is_array($info)){
					mobileJump('请先验证身份信息','index.php?act=member_index&op=mod_mobile');
					exit;
				}
				Tpl::output('step',true);
			}
			Tpl::showpage('member_mobile');
		}
	}
	
	//分享邀请明细列表
	public function member_invites_listOp(){
		/**
		 * 读取语言包
		 */
		Language::read ( 'member_member_invites' );
		$lang = Language::getLangContent ();
		$member_id = $_SESSION['member_id'];
		$sql = "SELECT * FROM #__member_invites  where member_id={$member_id}  and invite_type=2 ORDER BY id DESC";
		$pageSize = 10;
		$curPage = $_GET ['curpage'];
		$rs = db::PageQuery ( $sql, $curPage, $pageSize );
		$list = $rs->fetchAll ();
		$page = new Page ();
		$page->setEachNum ( $pageSize );
		$page->setNowPage ( $curPage );
		$page->setTotalNum ( $rs->pageRows () );
		$page->setStyle ( 'admin' );

		foreach( $list as $k => $v){
			$row = db::queryRow("SELECT M.member_mobile, M.member_areainfo, M.member_address, S.store_name FROM #__member AS M LEFT JOIN #__store AS S ON S.member_id = M.member_id WHERE M.member_id ='{$v['imember_id']}' LIMIT 1");
			$list[$k]['member_mobile'] = $row['member_mobile'];
			$list[$k]['member_address'] = $row['member_areainfo'] . ' ' .$row['member_address'];
			$list[$k]['store_name'] = $row['store_name'];
		}

		// 查询用户信息
		$member_model = new memberModel ();
		$member_info = $member_model->infoMember ( array (
			'member_id' => "{$_SESSION['member_id']}"
		) );
		if (! is_array ( $member_info ) || count ( $member_info ) <= 0) {
			showMessage ( Language::get ( 'predeposit_userrecord_error' ), 'index.php?act=member_snsindex', 'html', 'error' );
		}

		//分页
		$this->_assignMobileData($page);

		// 信息输出
		//self::profile_menu ( 'invites', 'invites' );
		Tpl::output ( 'menu_sign', 'invites' );
		Tpl::output ( 'menu_sign_url', 'index.php?act=member&op=invites' );
		Tpl::output ( 'menu_sign1', 'member_invites' );
//		Tpl::output ( 'show_page', $page->show () );
		Tpl::output ( 'list', $list );
		//Tpl::setLayout ( 'member_pub_layout' );

		Tpl::showpage ( 'member_invites' );
		
	
	}
	public function member_invites_detailsOp(){
		$add_time = date('Y-m-d',$_GET['add_time']);
		$store_name = $_GET['store_name'];
		$member_mobile = $_GET['member_mobile'];
		$member_address = $_GET['member_address'];
		$is_give = $_GET['is_give'];
		$use_state = $_GET['use_state'];
		$member_name = $_GET['member_name'];

		Tpl::output('add_time',$add_time);
		Tpl::output('store_name',$store_name);
		Tpl::output('member_mobile',$member_mobile);
		Tpl::output('member_address',$member_address);
		Tpl::output('is_give',$is_give);
		Tpl::output('use_state',$use_state);
		Tpl::output('member_name',$member_name);

		Tpl::showpage('member_invites_details');
		
	}

	

    /**
     *领取优惠券
     */
    public function ajax_optain_couponOp(){
        couponModel::drawCoupon();
    }

    /*领取现金券*/
    public function get_xjqOp(){
        xjqModel::receiveXjq();
    }
    /*提示领取现金券*/
    public function show_xjqOp(){
        Tpl::showpage ('show_xjq');
    }
}
